package com.tang.service.impl;

import com.tang.pojo.AuthInfo;
import com.tang.service.AuthLink;
import com.tang.service.AuthService;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Level2AuthLink extends AuthLink {

    private final LocalDateTime beginDate = LocalDateTime.of(LocalDate.of(LocalDate.now().getYear(), 6, 11), LocalTime.MIN);
    private final LocalDateTime endDate = LocalDateTime.of(LocalDate.of(LocalDate.now().getYear(), 6, 20), LocalTime.MAX);

    public Level2AuthLink(String levelUserId, String levelUserName) {
        super(levelUserId, levelUserName);
    }

    @Override
    public AuthInfo doAuth(String uId, String orderId, LocalDateTime authDate) {
        LocalDateTime dateTime = AuthService.queryAuthInfo(levelUserId, orderId);
        if (null == dateTime) { // 是否还未完成该级审批
            return new AuthInfo("0001", "单号：", orderId, "状态：待二级审批负责人", levelUserName);
        }
        AuthLink next = super.next();
        if (null == next || (authDate.isBefore(beginDate) || authDate.isAfter(endDate))) { // 是否有下级审批
            return new AuthInfo("0000", "单号：", orderId, "状态：二级审批完成负责人", "时间", dateTime.toString(), "审批人", levelUserName);
        }
        return next.doAuth(uId, orderId, authDate);
    }

}
